home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue32 / construc / DRBOBWIZ.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-03-08  |  4.7 KB  |  167 lines

  1. unit DrBobWiz;
  2. {$I-}
  3. {.$DEFINE WIZARD}
  4. interface
  5. uses
  6. {$IFDEF WIZARD}
  7.   ShareMem, VirtIntf, ExptIntf, ToolIntf,
  8. {$ENDIF}
  9.   Forms, DB, DBTables, SysUtils, StdCtrls, ExtCtrls, Controls, Classes, CheckLst;
  10.  
  11. type
  12.   TFormWizard = class(TForm)
  13.     Bevel: TBevel;
  14.     Notebook: TNotebook;
  15.     ButtonNext: TButton;
  16.     ButtonCancel: TButton;
  17.     ButtonBack: TButton;
  18.     Panel: TPanel;
  19.     Image: TImage;
  20.     ComboBoxAliases: TComboBox;
  21.     CheckListFields: TCheckListBox;
  22.     LabelFinish: TLabel;
  23.     MemoSQL: TMemo;
  24.     TheQuery: TQuery;
  25.     EditTitle: TEdit;
  26.     EditFileName: TEdit;
  27.     GroupBox: TGroupBox;
  28.     EditAction: TEdit;
  29.     RadioPost: TRadioButton;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure FormShow(Sender: TObject);
  32.     procedure ButtonStepClick(Sender: TObject);
  33.     procedure Precondition(Sender: TObject);
  34.   private
  35.     procedure BuildSQL;
  36.   public
  37.     Title: String;
  38.   {$IFDEF WIZARD}
  39.     procedure Finish(var ToolServices: TIToolServices);
  40.   {$ELSE}
  41.     procedure Finish;
  42.   {$ENDIF}
  43.   end;
  44.  
  45. implementation
  46. {$R *.DFM}
  47.  
  48. procedure TFormWizard.FormShow(Sender: TObject);
  49. begin
  50.   Title := Caption;
  51.   ButtonStepClick(Sender)
  52. end;
  53.  
  54. procedure TFormWizard.ButtonStepClick(Sender: TObject);
  55. begin
  56.   if Sender IS TButton then
  57.     NoteBook.PageIndex := NoteBook.PageIndex + (Sender AS TButton).Tag;
  58.   ButtonBack.Enabled := NoteBook.PageIndex > 0; { first }
  59.   if (NoteBook.PageIndex = 1) and ((Sender AS TButton).Tag = 1) then BuildSQL;
  60.   Caption := Title+Format(' %d/%d',[NoteBook.PageIndex+1,NoteBook.Pages.Count]);
  61.   if NoteBook.PageIndex < Pred(NoteBook.Pages.Count) then
  62.   begin
  63.     ButtonNext.Caption := '&Next >';
  64.     ButtonNext.ModalResult := mrNone
  65.   end
  66.   else { Finish }
  67.   begin
  68.     ButtonNext.Caption := '&Finish';
  69.     ButtonNext.ModalResult := mrOk
  70.   end
  71. end;
  72.  
  73. procedure TFormWizard.FormCreate(Sender: TObject);
  74. begin
  75.   Session.GetAliasNames(ComboBoxAliases.Items)
  76. end;
  77.  
  78. procedure TFormWizard.BuildSQL;
  79. var
  80.   i: Integer;
  81. begin
  82.   CheckListFields.Items.Clear;
  83.   with TheQuery do
  84.   begin
  85.     if ComboBoxAliases.Text <> '' then
  86.       DatabaseName := ComboBoxAliases.Text;
  87.     SQL := MemoSQL.Lines;
  88.     FieldDefs.Update { get info without executing TheQuery };
  89.     for i:=0 to Pred(FieldDefs.Count) do
  90.     begin
  91.       CheckListFields.Items.Add(FieldDefs[i].Name);
  92.       { only select the "parameterised" fields in the Query }
  93.       CheckListFields.Checked[i] :=
  94.         (Pos(UpperCase(':'+FieldDefs[i].Name),UpperCase(SQL.Text)) > 0) or
  95.         (Pos(UpperCase(':"'+FieldDefs[i].Name)+'"',UpperCase(SQL.Text)) > 0)
  96.     end
  97.   end
  98. end {BuildSQL};
  99.  
  100. procedure TFormWizard.Precondition(Sender: TObject);
  101. begin
  102.   ButtonNext.Enabled := EditFileName.Text <> ''
  103. end;
  104.  
  105. procedure TFormWizard.Finish{$IFDEF WIZARD}(var ToolServices: TIToolServices){$ENDIF};
  106. { do your Wizard execution here (modal result = mrOK) }
  107. var
  108.   f: System.Text;
  109.   Str: String;
  110.   i: Integer;
  111. begin
  112. {$IFDEF WIZARD}
  113.   if Assigned(ToolServices) then
  114. {$ENDIF}
  115.   begin
  116.     System.Assign(f,EditFileName.Text);
  117.     Rewrite(f);
  118.     writeln(f,'<HTML>');
  119.     writeln(f,'<BODY>');
  120.     writeln(f,'<H1>',EditTitle.Text,'</H1>');
  121.     writeln(f,'<HR>');
  122.     write(f,'<FORM ACTION="',EditAction.Text);
  123.     if RadioPost.Checked then writeln(f,'" METHOD=POST>')
  124.                          else writeln(f,'" METHOD=GET>');
  125.     writeln(f,'<UL>');
  126.     with TheQuery do
  127.     try
  128.       if ComboBoxAliases.Text <> '' then
  129.         DatabaseName := ComboBoxAliases.Text;
  130.       Str := MemoSQL.Text;
  131.       if Pos('WHERE ',UpperCase(Str)) > 0 then
  132.         System.Delete(Str,Pos('WHERE ',UpperCase(Str)),Length(Str));
  133.       SQL.Text := Str;
  134.       Open;
  135.       for i:=0 to Pred(CheckListFields.Items.Count) do if CheckListFields.Checked[i] then
  136.       begin
  137.         writeln(f,'<LI>',CheckListFields.Items[i],':');
  138.         writeln(f,'<BR><SELECT NAME="',CheckListFields.Items[i],'">');
  139.         First;
  140.         while not eof do
  141.         begin
  142.           writeln(f,'<OPTION VALUE="',FieldByName(CheckListFields.Items[i]).AsString,
  143.                                 '"> ',FieldByName(CheckListFields.Items[i]).AsString);
  144.           Next
  145.         end;
  146.         writeln(f,'</SELECT>');
  147.         writeln(f,'<P>')
  148.       end;
  149.       writeln(f,'</UL>');
  150.       writeln(f,'<CENTER>');
  151.       writeln(f,'<INPUT TYPE=RESET>');
  152.       writeln(f,'<INPUT TYPE=SUBMIT>');
  153.       writeln(f,'</FORM>');
  154.       writeln(f,'<HR>');
  155.       writeln(f,'<FONT SIZE=1>Generated by QueryBob (c) 1998 by Bob Swart (aka Dr.Bob - <A HREF="http://www.drbob42.com"TARGET=_top>www.drbob42.com</A>)</FONT>');
  156.       writeln(f,'</BODY>');
  157.       writeln(f,'</HTML>');
  158.       Close
  159.     finally
  160.       System.Close(f);
  161.     end
  162.   end
  163. end {Finish};
  164.  
  165. end.
  166.  
  167.